import {Plugin} from '../extend';
import {Color} from '../color';

export type HarmonyType =
    | 'analogous'
    | 'complementary'
    | 'double-split-complementary'
    | 'rectangle'
    | 'split-complementary'
    | 'tetradic'
    | 'triadic';

declare module '../color' {
    interface Color {
        /**
         * Returns an array of harmony colors as `Color` instances.
         */
        harmonies(type?: HarmonyType): Color[];
    }
}

/**
 * A plugin adding functionality to generate harmony colors.
 * https://en.wikipedia.org/wiki/Harmony_(color)
 */
const harmoniesPlugin: Plugin = (ColorClass: typeof Color): void => {
    /**
     * Harmony colors are colors with particular hue shift of the original color.
     */
    const hueShifts: Record<HarmonyType, number[]> = {
        analogous: [-30, 0, 30],
        complementary: [0, 180],
        'double-split-complementary': [-30, 0, 30, 150, 210],
        rectangle: [0, 60, 180, 240],
        tetradic: [0, 90, 180, 270],
        triadic: [0, 120, 240],
        'split-complementary': [0, 150, 210]
    };

    ColorClass.prototype.harmonies = function(type = 'complementary') {
        return hueShifts[type].map((shift) => this.rotate(shift));
    };
};

export default harmoniesPlugin;
